# Create your views here.
from rest_framework.generics import CreateAPIView, RetrieveAPIView
from rest_framework.response import Response

from .models import User
from .serializers import CompanyUserInfoSerializer, UserSerializer


class UserCreateViewSet(CreateAPIView):
    queryset = User.objects.all()
    serializer_class = UserSerializer

    def create(self, request, *args, **kwargs):
        user = User.objects.create_user(**request.data)
        return Response({"id": user.id, "username": user.username})


class CompanyUserInfoViewSet(RetrieveAPIView):
    """用户
    """
    queryset = User.objects.all()
    serializer_class = CompanyUserInfoSerializer

    def retrieve(self, request, *args, **kwargs):
        serializer = self.get_serializer(request.user)
        return Response(serializer.data)
